
{% extends 'authuser/base.html' %}
{% block content %}
<script type="text/javascript">
	
		app.controller('content',function ($scope,$http) {
			// 
			$scope.next="{{next |default:'/'}}";
			$scope.regist_url='{{regist_url}}'

			//
			$scope.user={
				name:'',
				password:''
			}
			$scope.infome=false;
			$scope.submit_func=function (valid) {
				if(!valid){
					$scope.infome=true;
				}else{
					$scope.infome=false;
					var postData={
						do_login:{name:$scope.user.name,password:$scope.user.password}
					}
					$http.post('',postData)
					.success(function(data, status, headers, config) {  
					    if(data.msg){
						    alert(data.msg)
					    }
						if(data.do_login.status=='success'){
							$scope.stdout='登陆成功';
							location=$scope.next;
						}else{
							alert(data.do_login.msg)
						}
					}).error(function(data, status, headers, config) {  
					    alert('有错误,返回码为:'+status)
					});  
				}
			};
			$scope.logout=function () {
					var postData={
						logout:{},
					};
					$http.post('',postData)
				.success(function(data, status, headers, config) {  
				    //加载成功之后做一些事  
					$scope.stdout="提交成功";
					if(data.status=='success'){
						$scope.stdout='退出成功';
						location=$scope.next;
					}
				}).error(function(data, status, headers, config) {  
				    //处理错误 
				    $scope.stdout='有错误,返回码为:',
				    $scope.stdout+=status; 
				});  
				};
		});
</script>
<div class='container'>
	<div ng-controller='content'>
		<form name="logForm" ng-submit='submit_func(logForm.$valid)' class='form-signin' novalidate>
			<h2 class='form-signin-heading'>欢迎登陆</h2>
			
			<input type="test" 
				class='form-control' 
				name='name' 
				placeholder='用户名' 
				ng-model='user.name' 
				required autofocus>
			<input type="password" 
				class='form-control'
				name="pswd" 
				placeholder='password' 
				ng-model='user.password' 
				required />
	
			<input type="submit" 
				class='btn btn-lg btn-primary btn-block' 
				value="登陆" />
			<div style='text-align: right;padding-top:10px;'>
				<a ng-href="[[regist_url]]" >注册</a>
			</div>
			<div ng-show='infome' style='color: red;'>
				<p ng-show='logForm.name.$error.required'>* 用户名不能为空</p>
				<p ng-show='logForm.pswd.$error.required'>* 密码不能为空</p>
			</div>
			
		</form>
	<!--</div>-->
	
	<!--<div ng-if='is_login'>
		<div>已经登陆了... <a ng-href='[[next]]'>返回</a><a href="" ng-click="logout()">登出</a></div>
	</div>-->
	
	<div ng-bind='stdout' class='form-signin' style='color:red'></div>
</div>

</div>
<style type="text/css">
	.form-signin{
		max-width:330px;
		padding: 15px;
		margin: 0 auto;
	}
	input{
		margin-bottom:3px;
	}
</style>

{% endblock %}